package com.yinhe.module.ls.controller;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhEnterpriseLeader;
import com.yinhe.system.service.IYhEnterpriseLeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 承制单位领导信息Controller
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/ls/leader")
public class LsEnterpriseLeaderController extends BaseController
{
    @Autowired
    private IYhEnterpriseLeaderService yhEnterpriseLeaderService;

    /**
     * 查询承制单位领导信息列表
     */
    @PreAuthorize("@ss.hasPermi('module:ls:leader:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhEnterpriseLeader yhEnterpriseLeader)
    {
        startPage();
        List<YhEnterpriseLeader> list = yhEnterpriseLeaderService.selectYhEnterpriseLeaderList(yhEnterpriseLeader);
        return getDataTable(list);
    }

    /**
     * 导出承制单位领导信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:leader:export')")
    @Log(title = "承制单位领导信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhEnterpriseLeader yhEnterpriseLeader)
    {
        List<YhEnterpriseLeader> list = yhEnterpriseLeaderService.selectYhEnterpriseLeaderList(yhEnterpriseLeader);
        ExcelUtil<YhEnterpriseLeader> util = new ExcelUtil<YhEnterpriseLeader>(YhEnterpriseLeader.class);
        util.exportExcel(response, list, "承制单位领导信息数据");
    }

    /**
     * 获取承制单位领导信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leader:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhEnterpriseLeaderService.selectYhEnterpriseLeaderById(id));
    }

    /**
     * 新增承制单位领导信息
     */
    @PreAuthorize("@ss.hasPermi('system:leader:add')")
    @Log(title = "承制单位领导信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhEnterpriseLeader yhEnterpriseLeader)
    {
        return toAjax(yhEnterpriseLeaderService.insertYhEnterpriseLeader(yhEnterpriseLeader));
    }

    /**
     * 修改承制单位领导信息
     */
    @PreAuthorize("@ss.hasPermi('system:leader:edit')")
    @Log(title = "承制单位领导信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhEnterpriseLeader yhEnterpriseLeader)
    {
        return toAjax(yhEnterpriseLeaderService.updateYhEnterpriseLeader(yhEnterpriseLeader));
    }

    /**
     * 删除承制单位领导信息
     */
    @PreAuthorize("@ss.hasPermi('system:leader:remove')")
    @Log(title = "承制单位领导信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhEnterpriseLeaderService.deleteYhEnterpriseLeaderByIds(ids));
    }
}
